﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ReworkManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ReworkManagement.ReworkTypeVMs
{
    public partial class ReworkTypeListVM : BasePagedListVM<ReworkType_View, ReworkTypeSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ReworkType_View>> InitGridHeader()
        {
            return new List<GridColumn<ReworkType_View>>{
                
                this.MakeGridHeader(x => x.ReworkType_ReworkTypeCode).SetTitle(@Localizer["Page.返工类型"].Value),
                this.MakeGridHeader(x => x.ReworkType_TypeDesc).SetTitle(@Localizer["Page.返工说明"].Value),
                this.MakeGridHeader(x => x.ReworkType_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ReworkType_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ReworkType_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ReworkType_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.ReworkType_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ReworkType_View> GetSearchQuery()
        {
            var query = DC.Set<ReworkType>()
                
                .CheckContain(Searcher.ReworkTypeCode, x=>x.ReworkTypeCode)
                .CheckContain(Searcher.TypeDesc, x=>x.TypeDesc)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ReworkType_View
                {
				    ID = x.ID,
                    
                    ReworkType_ReworkTypeCode = x.ReworkTypeCode,
                    ReworkType_TypeDesc = x.TypeDesc,
                    ReworkType_CreateTime = x.CreateTime,
                    ReworkType_UpdateTime = x.UpdateTime,
                    ReworkType_CreateBy = x.CreateBy,
                    ReworkType_UpdateBy = x.UpdateBy,
                    ReworkType_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ReworkType_View: ReworkType
    {
        
        public string ReworkType_ReworkTypeCode { get; set; }
        public string ReworkType_TypeDesc { get; set; }
        public DateTime? ReworkType_CreateTime { get; set; }
        public DateTime? ReworkType_UpdateTime { get; set; }
        public string ReworkType_CreateBy { get; set; }
        public string ReworkType_UpdateBy { get; set; }
        public bool ReworkType_IsValid { get; set; }

    }

}